Reactive expression generation and optimization

ABSTRACT

Reactive programming is facilitated. Reactive expressions can be generated automatically from non-reactive expressions or in other words standard expressions. Additionally or alternatively, reactive expressions can be optimized in a number of different ways to minimize computational work.

BACKGROUND

Computer programs are often specified with one or more expressions, forinstance as a component of a statement. An expression is a combinationof values, constants, variables, operators, and a function that isinterpreted in accordance with rules of precedence of a particularprogramming language. An expression can be computed, or in other wordsevaluated, the result of which is a value of some type (e.g., integer,string, Boolean . . .). By way of example, an arithmetic and programmingexpression can be “1+2” which can evaluate to “3.” Similarly, anexpression can correspond to “x+2,” wherein “x” is a pointer to a valuein memory. Further, “5>4” is an example of a relational, or Boolean,expression that evaluates to true. Evaluated expressions can have sideeffects meaning that in addition to returning a value there is asecondary, typically undesirable, effect such as a change in some state.

SUMMARY

The following presents a simplified summary in order to provide a basicunderstanding of some aspects of the disclosed subject matter. Thissummary is not an extensive overview. It is not intended to identifykey/critical elements or to delineate the scope of the claimed subjectmatter. Its sole purpose is to present some concepts in a simplifiedform as a prelude to the more detailed description that is presentedlater.

Briefly described, the subject disclosure pertains to facilitatingreactive programming. In accordance with one aspect of the disclosure, areactive expression can be generated automatically based on anon-reactive, or standard, expression. In accordance with anotheraspect, a reactive expression, whether generated from a non-reactiveexpression or not, can be optimized by applying one or more of a myriadof optimization techniques, for example to avoid duplicating sideeffects and eliminate excessive reevaluation, and improve performanceoverall.

To the accomplishment of the foregoing and related ends, certainillustrative aspects of the claimed subject matter are described hereinin connection with the following description and the annexed drawings.These aspects are indicative of various ways in which the subject mattermay be practiced, all of which are intended to be within the scope ofthe claimed subject matter. Other advantages and novel features maybecome apparent from the following detailed description when consideredin conjunction with the drawings.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a block diagram of a reactive programming system.

FIG. 2 illustrates implementation of a spreadsheet model utilizingdisclosed aspects.

FIG. 3 is a block diagram of a representative optimization component.

FIG. 4 is a block diagram of a representative side effect component.

FIG. 5 is a block diagram of a reactive expression system including adomain optimization component.

FIG. 6 is a flow chart diagram of a method of facilitating reactiveprogramming.

FIG. 7 is a flow chart diagram a method of optimizing a reactiveexpression.

FIG. 8 is a flow chart diagram of a method of optimizing a reactiveexpression.

FIG. 9 is a flow chart diagram of a method of optimizing a reactiveexpression.

FIG. 10 is a schematic block diagram illustrating a suitable operatingenvironment for aspects of the subject disclosure.

DETAILED DESCRIPTION

Details below are generally directed toward facilitating reactiveprogramming or more particularly reactive expression generation andoptimization. Building reactive programs that propagate input updates(a.k.a. reactive programming) requires quite a bit of plumbing code, or,in other words, behind-the-scenes low-level code. Often a programmer'sintent gets lost in the process of defining a reactive expression. Toaddress this issue, a mechanism is provided to generate a reactiveexpression from non-reactive expression. Stated differently, a standardexpression can be lifted to a reactive expression. Consequently, aprogrammer can specify a standard expression (e.g., function) that cansubsequently be utilized to produce a reactive expression automatically.Moreover, a reactive expression can be optimized to in many differentways to minimize computational work associated with propagating updatesupon changes to inputs, among other things. By way of example and notlimitation, reactive expressions can be generated that avoid duplicateside effects, eliminate excessive reevaluation, and improve performanceoverall (e.g., executes faster, more efficiently . . . ).

Various aspects of the subject disclosure are now described in moredetail with reference to the annexed drawings, wherein like numeralsrefer to like or corresponding elements throughout. It should beunderstood, however, that the drawings and detailed description relatingthereto are not intended to limit the claimed subject matter to theparticular form disclosed. Rather, the intention is to cover allmodifications, equivalents, and alternatives falling within the spiritand scope of the claimed subject matter.

Referring initially to FIG. 1, a reactive programming system 100 isillustrated. The system 100 includes a generation component 110configured to generate a reactive expression based on a non-reactive, orin other words standard, expression. A non-reactive expression such as afunction changes solely in response to evaluation. Conversely, areactive expression changes in response to changes in input. By way ofexample, consider the expression “a=b+c,” meaning “a” is assigned theresult of the sum of “a” and “b.” If this is a standard, ornon-reactive, expression, “a” is assigned the result of “b+c” theinstant the expression is evaluated. Subsequently, if “b” or “c” change,the change will have no effect on the value of “a.” If the expression isa reactive expression, the value of “a” would automatically be updatedbased on new values of either or both of “b” and “c.” Conventionally,specifying a reactive expression requires quite bit ofbehind-the-scenes, low-level, boilerplate code. As a result, aprogrammer's intent is lost in the process of defining reactivefunctionality. The generation component 110 enables a programmer tosimply specify a standard, non-reactive expression and subsequently havean equivalent reactive expression, or reactive version thereof,generated automatically. Further, the generation component 110 can beapplied to legacy programs, and more specifically expressions therein,to produce reactive versions.

The generation of reactive expressions by the generation component 110can occur in several different ways, all of which are within the scopeof the appended claims. In one instance, program code can be added to anon-reactive expression to generate a reactive expression. Additionallyor alternatively, a non-reactive expression can be converted orotherwise transformed or translated from a non-reactive expression to areactive expression. Still further yet, a new reactive expression can beproduced as a function of a non-reactive expression.

Generation of a reactive expression from a non-reactive expression canbe embodied within a “Lift” function in accordance with one aspect.Consequently, generation of a reactive expression can be termed liftingof a non-reactive expression to a reactive expression, or simply liftingor various forms thereof herein. By way of example, a set of operatorscan be built that have the following signature:

Lift : : (T₁ × ... × T_(n) → R) → (IO<T₁> × ... × IO<T_(n)> → IO<R>)In other words, operators can take a standard expression, such as afunction, over arguments of types “T₁” through “T_(n)” (where “n” is aninteger greater than or equal to zero) and with a return type “R.” As aresult, the operators produce a lifted expression that accepts “IO<T>”variants of the arguments and returns “IO<R>” variant of the resulttype, where “IO<T>” and “IO<R>” refer to “IObservable<T>” and“IObservable<R>” an interface (e.g., provider) that represents a classthat sends push-based notifications of type “T” or “R” to an observer inaccordance with an observer design pattern.

One possible approach to implement the desired lifting behavior is toconstruct an observable sequence (e.g., push-based data source) out ofinput sequences using a “CombineLatest” operator (e.g., merges twoobservable sequences into one sequence whenever one of the observablesequences has a new value) and supplying a function as an argument. Forexample:

Func<IObservable<T1>, IObservable<T2>, IObservable<R>> Lift<T1, T2,R>(Func<T1, T2, R> f) {  return (o1, o2) => o1.CombineLatest(o2, f); }For functions of higher arity, or, in other words, greater number ofarguments than two, “CombineLatest” operators with higher arity could besupplied to make the lifting process as straightforward, as shown above.Alternatively, intermediate combiner functions could be used. Forinstance:

Func<IObservable<T1>, IObservable<T2>, IObservable<T3>, IObservable<R>>Lift<T1, T2, T3, R> (Func<T1, T2, T3, R> f) {  return (o1, o2, o3) =>o1.CombineLatest(o2, (a, b) =>   new { a, b }) .CombineLatest(o3, (ab,c) => f(ab.a, ab.b, c)); }The above allocates many intermediate objects, so higher arity“CombineLatest” overloads may be preferred. That being said, forfunctions of arbitrary number of arguments, it is likely regardless ofthe number of “CombineLatest” overloads, the technique above may stillplay a role (e.g., lifter is presented for arbitrary functions, usingexpression trees). Further, instead of using anonymous types forintermediate projections, built-in tuple types could be used as well.For example:

Func<IObservable<T1>, IObservable<T2>, IObservable<T3>, IObservable<R>>Lift<T1, T2, T3, R>(Func<T1, T2, T3, R> f) {  return (o1, o2, o3) =>o1.CombineLatest(o2, (a, b) =>   new Tuple<T1, T2>(a,b)).CombineLatest(o3, (t, c) => f(t.Item1,   t.Item2, c)); }

One example where reactive-type expressions are utilized is inspreadsheet programs. For example, spreadsheet cells can include literalvalues or formulas such as “B1+C1” that are evaluated based on values ofother cells. Whenever a value of a dependent cell changes, the valueresulting from the formula will be updated. However, conventionallythese type of reactive expressions are tightly coupled to the notion ofcells as well as their internal representation and as such cannotoperate over arbitrary reactive (e.g., push-based) data sources. As usedherein, a reactive expression refers to expressions that arecontinuously evaluated over time wherein reevaluation is triggered uponalterations to one or more of an expression's sub-expressions ordependencies, which can themselves be reactive expressions. Moreover,reactive expressions as referred to herein are intended to be moregeneral than similar spreadsheet expressions and operate over anyreactive/observable data source.

FIG. 2 illustrates implementation of a spreadsheet model utilizingdisclosed aspects to facilitate clarity and understanding. A simplespreadsheet 210 is illustrated with six total cells. Cells “A1” and “B1”include literal values, namely “42” and “21.” Cell “A2” includesexpression 212 which indicates “A2=A1/B1.” Cells are identified at 214as standard integers. After a lift operation is performed, the samecells are transformed into observables of type integer. Code 222 isgenerated to transform the non-reactive expression 212 into a reactiveexpression.

Turning attention back to FIG. 1, the reactive programming system 100can also include an optimization component 120. The generation component110 can be basic in nature with respect to generation of a reactiveexpression. The optimization component 120 can enable a moresophisticated approach to reactive expression generation. Morespecifically, the optimization component 120 can be configured toacquire a reactive expression and generate an optimized reactiveexpression, or, in other words, an optimized version of a reactiveexpression. Various optimization techniques can be employed to minimizethe amount of computational work required to propagate updates to one ormore inputs and generate a new output, among other things. Code can beadded, deleted, or altered with respect to code that enables a reactivebehavior. Optimizations can be performed at compile time or dynamicallyat runtime utilizing a compiler or other system. Further, optimizationscan be governed by various inputs including user specified policies orother data. Further yet, a feedback loop can be employed to optimize areactive expression continuously given past performance information orcurrent context information, for example. Additionally, it should beappreciated that the optimization component 120 can be employed outsidethe context of generation of a reactive expression from a non-reactiveexpression, for instance, where a reactive expression already exists(e.g., manually coded, generated with a different system . . . ).

FIG. 3 depicts a representative optimization component 120 in furtherdetail. The optimization component 120 includes side effect component310, which can be configured to avoid at least duplicate (e.g., two ormore) side effects. Expressions can have side effects duplicates ofwhich are undesirable. For instance, if an expression causes a creditcard to be charged it is desirable to not perform the action more than arequired number of times (e.g., once). More specifically, if a functionis supplied with the same observable source for multiple arguments, useof a “CombineLatest” operator will result in multiple subscriptions.This in turn causes duplicate side effects. By way of example, if anexpression includes “A1+A1,” this can cause duplicate subscriptions tothe same observable source resulting in potentially duplicate sideeffects. By detecting duplicate input sequences and coalescing theirsubscriptions, duplicate side effects can be avoided. Of course, otherapproaches can be employed including leaving the responsibility ofavoiding at least duplicate side effects to a caller or performing insome desired manner configurable with a policy flag.

FIG. 4 illustrates a representative side effect component 310 in furtherdetail including source analysis component 410, publication component420, and rewriter component 430. The source analysis component 410 canbe configured to analyze input observable sequences and filter outduplicates, or, in other words, identify unique sequences, as a functionof object identity checks. For example, consider a standard expression“a*b+c.” Here, it can be determined, for example at run time, that “a”and “c” correspond to, or derive from, the same input sequence orsource. As a result, an index map 412 or similar structure can begenerated by the source analysis component 410 indicating that “a” and“b” are unique and “a” and “c” correspond to the same input sequence orsource.

Note that the source analysis component 410 can be configured to utilizeother mechanisms beyond object identity to filter out duplicates oridentify unique sequences or sources. For instance, if some inputsequences represent expressions with the same meaning this could bedetected using an advanced comparer or equality function. Consider, forexample, the query expression “from x in xs where x % 2==0 select x”appearing multiple times (e.g., recursively) for the same “xs” source.More generally, the source analysis component 410 can be configured toperform more intelligently tracing common sub-query expressions fromroots (e.g., query sources) down. For instance, consider two queryexpressions “from x in xs where x % 2==0 select x” and “from x in xswhere x % 2==0 select x+1.” Those are the same expressions except forthe projection parts, “select x” versus “select x+1.” Accordingly, theremainder, “from x in xs where x % 2==0,” can be reused. Generally, thesource analysis component 410 can be configured to delineate shareablecomputation. Stated differently, the source analysis component 410 canbe configured to detect common sub-expressions

The publication component 420 can be configured to alias unique sourcesas determined by the source analysis component 410 for multiple use byemploying a “Publish” operator, for example:

IObservable<R> Publish<T, R> (IObservable<T> source,Func<IObservable<T>, IObservable<R>> f);Since multiple distinct sources can occur, “Publish” operators withhigher arity can be introduced to simplify publication of many sourcessimultaneously (e.g., using T1, T2 . . . Tn for generic parameters forsources and the function parameter). Regardless of how many sources areutilized by an expression, the result can be that a single subscriptionto such sources is established.

The source analysis component 410 and the publication component 420 canexchange information about shared sources as well as how the sharedsources are used. For instance, sources can be tagged with theirparameter position. This index matches the parameter position in areactive expression. For example, “Lift((a, b, c,)=>a*b+c) (xs, ys, xs)”results in two distinct sources “xs” and “ys.” The first source “xs” canhave indices “0” and “2,” and the second source “ys” can have index “1.”Unique sources can be published resulting in an alias within apublication function (e.g., publish code 422) where they can be usedmultiple times as described earlier. In the running example, thisresults in the following skeleton: “Observable.Publish(xs, ys, (xs_,ys_)=>. . . .” The body of the publication function can be supplied witha lifted computation. Its input includes the map of function parameterindices on to the (aliased) sources represented in an index map 412. Inthe running example, “0” maps to “xs_,” “1” maps to “ys_,” and “2” mapsto “xs_.” In other words, the parameters “a,” “b,” and “c” are drawnfrom “xs_,” “ys_,” and “xs_,” respectively. Notice the side effectcomponent 310 can be smart about redundant publications. For instance,above, the “ys” source is published even though it is only used once. Anoptimization can be to eliminate this redundant step. Code can begenerated dynamically here based on detected equalities of sourcesprovided to a lift function, for example.

Residual expressions for an extracted common source expressions can becommunicated as well. For example, “Lift((a, b)=>a+b)(xs.Where(x=>x %2==0, xs.Where(x=>x % 2==0).Select(x=>x+1))” could result in publicationof the common sub-expression “xs.Where(x=>x % 2==0)” if “xs” indeed isthe same source for both uses. In this case, a parameter index map 412can include additional information about the residual expression to beapplied after publication. In the running example, “xs.Where(x=>x %2==0)” now acts as a common source with indices “0” and “1.” However,for index “0” the residual expression can be set to null, while index“1” carries the residual expression “.Select(x=>x+1). The common sourcecan still be published once, with the aliased source being carriedforward, “xs.Publish (xs_=>. . . ).” However, the index map with theresidual expressions can be carried along as well. Inside the expressionfor the publication function, uses of “a” in the lifted function can bedrawn from “xs_” (as index 0, corresponding to “a” does not have aresidual expression), while uses of “b” can be drawn to “xs_” too, afteruse of the residual “xs_.Select(x=>x+1)” expression (conform index 1'sentry in the map).

The rewriter component 430 can be configured to rewrite an expressioninto a reactive expression. It can use the index map 412 for parametersto the originating sources, supplied by the source analysis component410 and/or publication component 420. The rewriter component 430 can beconfigured to analyze a function's parameters in order, querying theindex map 412 for the sources that will provide the values correspondingto the parameter after lifting. After doing this mapping, a chain of“CombineLatest” operator calls can be built and the original function issupplied as the body (e.g., CombineLatest code 433). For example,consider again “Lift((a, b, c)=>a*b+c)(xs, ys, xs).” The functiongenerated by lift include logic that 1) detected duplicate use ofsequence “xs,” resulting in an index map: “xs −>0, 2” and “ys−>1;” 2)inserted a publish call for at least “xs” as it gets reused:“xs.Publish(xs_=>. . . ); and 3) kept track of the mapping of “xs_−>0(a), 2(c)” and “ys−>1(b). The rewriting component 430 can now build upthe publish body using “CombineLatest” calls for sources being used.Sources that are only used once can go without a prior “Publish:”“xs_=>xs_.CombineLatest(ys, (x, y)=>. . . ).” Using the index map, the“CombineLatest” combiner function parameters can be mapped onto thesupplied function being lifted. In this case, both “a” and “c” map onto“x” and “b” maps onto “y:” “(x, y)=>x*y+x.” As will be discussed later,calls to “DistinctUntilChanged” can be interwoven with the expressionbeing created for the “CombineLatest” calls.

Returning to FIG. 3, the optimization component 120 also includesreevaluation component 320 that can be configured to limit thereevaluation, or, in other words, re-computation, of an expression wherepossible. For example, in one instance reevaluation can be restricted toinstances where an input sequence value changes. If an expression isreevaluated upon every change, there can be duplicate values thatunnecessary trigger reevaluation. Accordingly, the reevaluationcomponent 320 can be configured to initiate reevaluation of distinctvalues or in other words values that differ from a previous value. Inaccordance with one implementation, this can be accomplished byutilizing a “DistinctUntilChanged” operator.

By way of example and not limitation, consider the following piece ofcode:

var f = Lift((a, b, c) => f1(a) * f2(b) + f3(c)) ;Assuming all three inputs to “f” are unique, the rewrite can look asfollows:

(o1, o2, 03) => o1.CombineLatest (  o2, (x, y) => f1 (x) * f2(y)).CombineLatest(o3, (t, z) => t + f3(z))Now a change to “o1” would trigger reevaluation of “f1(x)*2(y).”However, if that result does not change from the previous computed valueof “f f1(x)*f2(y)” (with “x” being the previous element from “o1”), theevaluation triggered by the “CombineLatest(o3, . . . )” is redundant. Wecan cut off the computation at this point by injecting“DistinctUntilChanged” calls:

 (o1, o2, o3) => o1.CombineLatest(o2, (x, y) => f1 (x) * f2(y)).DistinctUntilChanged ( ) .CombineLatest(o3, (t, z) => t + f3 (z))In fact, this reduction of change propagation can be based on furtheranalysis of the expression of a function. In the sample shown here,“f1(x)” (and any other such function application) is a black box whoseoutcome may be the same for many values of “x.” Even though the sourceof such values “x” (in the sample, “o1”) may signal updates, “f1(x)” mayremain stable. For instance, consider a function that multiplies aninput value by zero. A rewrite can be used to delineate islands ofreevaluation as follows:

 (o1, o2, o3) => o1.Select (x => f1 (x)) .DistinctUntilChanged ( ).CombineLatest (o2.Select (y => f2 (y)) .DistinctUntilChanged( ), (x _,y_) => x_ * y_) .CombineLatest(o3.Select (z => f3 (z)).DistinctUntilChanged ( ), (t, z_) => t + z_)In other words, the “DistinctUntilChanged” operation can be positionedclose to an input source to identify distinct contiguous elements orhigher up with respect to operations over the input. The particularposition is configurable and dependent upon properties of a functionitself (e.g., number of unique values, distribution of values . . . ).In operation, a cache can be maintained of a previous element to which acomparison can be made to a subsequent element to determine whether aninput element is distinct.

The optimization component 120 can also include one or moredomain-specific components 330 that optimize a reactive expression basedon specific domains or domain information. Below illustrates use of ahypothetical math-savvy embodiment of a domain-specific component 330.Consider for or example:

var f = Lift ((a, b, c) => a * b + c);Here, a programmer has specified that the lambda expression “(a, b,c)=>a*b+c” be lifted or in other words that a reactive version of thelambda expression be generated and the output be assigned to “f.” Atthis point, the expression cannot be optimized and as a result a genericpiece of code can be generated that can accept any three observablesequences as input. However, if the inputs corresponding to the liftedparameters “a” and “c” happen to be the same sequence, things can beoptimized to:

var res = f (xs, ys, xs);As we previously discussed, this can be rewritten into:

xs.Publish (xs_ => xs_.CombineLatest (ys, (x, y) => x * y + x));However, now a rewrite of the function can be accomplished to simplifyit, as “a” and “c” now contain the same value “x.” Now “x” can befactored out as follows:

xs.Publish (xs_ => xs_.CombineLatest (ys, (x, y) => (x + 1) * y));Such optimization is domain-specific with respect to types of sequencesinvolved—here, observable sequences of integers.

Additionally or alternatively, specific optimization functionality canbe external to the optimization component 120 as shown system 500 ofFIG. 5. System 500 includes the generation component 110 and theoptimization component 120 previously described. The system 500 furtherdepicts the domain optimization component 510 communicatively coupledwith and external to the optimization component 120. Such an externaldomain optimization component 510 can be discovered from one or moresources based on the type of sequences involved in an expression, forexample. The domain optimization component 510 can optionally utilizeexternal information and a feedback loop in in its optimization. Theoutput of the domain optimization component 510 can be a domainoptimized reactive expression. Furthermore, although depicted asdependent upon the optimization component 120 this is not required. Infact, the domain optimization component 510 a reactive expression(optimized or not) can be passed through by way of the optimizationcomponent 120 or received or retrieved directly.

A variety of other optimization strategies can be applied by way of theoptimization component 120. By way of example and not limitation,frequency of change can be utilized as a basis for optimization. Areactive expression can be coded to account for the frequency at whichan input source provides elements or in other words the “chattiness” ofa source. Where an expression is represented in an expression tree,optimization can correspond to rebalancing the expression, here forfrequency of change. Generally, it is desirable to utilize the shortestpath for things that change most often. For example, suppose you havethree inputs “A,” “B,” and “C,” and “C” changes fast. Accordingly, anoptimization would be to perform a “CombineLatest” operation on “A” and“B,” and then a “CombineLatest” operation on with “C.” Now “C” has theshortest path length. This is analogous to an organizational structurein which the most important person is closest to the top with the leastamount of communication delay, or, in other words, the least amount ofmanagers interfering. Further, the frequency at which sources change canvary over time, a reactive expression can be re-optimized in light ofthe frequency of change of input sequences.

Optimization techniques can be controlled through a user specifiedpolicy. By way of example and not limitation, consider utilization of a“DistinctUntilChanged” operator. This operator is expensive in that itneeds to maintain state, namely the last element that was provided by asource. If the source does not have adjacent elements that are the same,use of the operator is wasteful. Accordingly, a user can configure whensuch an operator and thus an optimization is employed. Imagine a globalpositioning system (GPS) that supplies location information every secondand has a resolution of one-hundred feet. If an individual is walking,use of a “DistinctUntilChanged” operator is useful, as it will take sometime before new value is received upon journeying one-hundred feet.However, if the same individual is traveling in a car on the highway,use of the operator does not make much sense since it is unlikely thatany values will be thrown away. Further, expiration policies can beestablished as well that invalidate caches housing elements forcomparison to determine distinct elements.

Optimization can be performed dynamically based on runtime analysis orstatically at compile time upon inspection of an expression supplied bya user. Dynamic optimization can involve analyzing supplied observablesequences or sources and emitting specialized code based on the inputs,for example. Static optimization can involve analyzing a non-reactiveexpression and eliminating redundant parameters (e.g., (a, b)=>a),sharing computation (e.g., using distributive laws . . . ), forinstance. Furthermore, an implementation of a reactive expression can bedynamically readjusted. In this case, a threshold, policy, or costbenefit analysis can be employed to determine if, and when, to readjustthe implementation to optimize execution further.

The aforementioned systems, architectures, environments, and the likehave been described with respect to interaction between severalcomponents. It should be appreciated that such systems and componentscan include those components or sub-components specified therein, someof the specified components or sub-components, and/or additionalcomponents. Sub-components could also be implemented as componentscommunicatively coupled to other components rather than included withinparent components. Further yet, one or more components and/orsub-components may be combined into a single component to provideaggregate functionality. Communication between systems, componentsand/or sub-components can be accomplished in accordance with either apush and/or pull model. The components may also interact with one ormore other components not specifically described herein for the sake ofbrevity, but known by those of skill in the art.

Furthermore, various portions of the disclosed systems above and methodsbelow can include or employ of artificial intelligence, machinelearning, or knowledge or rule-based components, sub-components,processes, means, methodologies, or mechanisms (e.g., support vectormachines, neural networks, expert systems, Bayesian belief networks,fuzzy logic, data fusion engines, classifiers . . . ). Such components,inter alia, can automate certain mechanisms or processes performedthereby to make portions of the systems and methods more adaptive aswell as efficient and intelligent. By way of example and not limitation,such mechanisms can be to infer reactive expression optimizations.

In view of the exemplary systems described supra, methodologies that maybe implemented in accordance with the disclosed subject matter will bebetter appreciated with reference to the flow charts of FIGS. 6-9. Whilefor purposes of simplicity of explanation, the methodologies are shownand described as a series of blocks, it is to be understood andappreciated that the claimed subject matter is not limited by the orderof the blocks, as some blocks may occur in different orders and/orconcurrently with other blocks from what is depicted and describedherein. Moreover, not all illustrated blocks may be required toimplement the methods described hereinafter.

Referring to FIG. 6, a method of facilitating reactive programming 600is illustrated. At reference numeral 610, a reactive expression isgenerated, for example based on a non-reactive, or standard, expressionspecified by a program. In other words, non-reactive expression can belifted to a reactive expression. For instance, an observable sequencecan be constructed out of input sequences using a “CombineLatest”operator and supply a non-reactive expression, such as a function, as anargument. At reference numeral 620, the reactive expression isoptimized. Stated differently, an optimized version of a reactiveexpression is generated. A myriad of novel or known optimizationtechniques can be utilized including but not limited to filtering outsubscriptions to duplicate input sequences to avoid duplicate sideeffects or improve performance, and restricts reevaluation of a reactiveexpression, or change propagation, to instances where an input sequencevalue changes to limit excess reevaluation.

FIG. 7 depicts a method 700 of optimizing a reactive expression. Atreference numeral 710, a unique sub-expression(s) within a reactiveexpression is identified. Code is generated, at 720, to identify asource of input for the sub-expression, for example based on objectidentifiers. At reference numeral 730, code can be generated to filterout duplicate sources of input for sub-expressions. As a result,subscriptions to observable sequences, or sources of input, are limitedthereby avoiding duplication of side effects and improving performance.

FIG. 8 illustrates a flow chart diagram of a method 800 of optimizing areactive expression. At numeral 810, input is acquired from a source.For example, an observable sequence can push values to observer inaccordance with a subscription to the observable sequence. At referencenumeral 820, a determination is made as to whether the input is the sameas the previous, or last provided, input. For example, cache can bemaintained including the last provided value for comparison purposes.If, at 820, the input is the same (“YES”), the method terminates and ineffect discards the input. Alternatively, if the input is not the samebut rather is distinct from a contiguous value (“NO”), one or moreelements associated with the source can be updated at reference 830.

FIG. 9 depicts a method 900 of optimizing a reactive expression. Atreference numeral 910, a frequency of data source change is computed. Inother words, the chattiness of an input source is determined At numeral920, a determination is made as to whether a threshold has been met asspecified with respect to a policy for example. Stated differently, thedetermination concerns whether it is prudent to modify an implementationof a reactive expression for example based a specific frequency orchange in frequency, or on a cost/benefit analysis with the cost beingthat associated with making a change and the benefit being the effect ofan implementation alteration. If a threshold has not been met (“NO”),the method can simply terminate. However, if at 920 it is determinedthat a threshold has been met (“YES”), the method proceeds at numeral930 where a reactive expression is optimized based on the frequency ofdata source change. For example, source associated with the greatestfrequency of change can be positioned with the shortest path length.

As used herein, the terms “component” and “system” as well as formsthereof are intended to refer to a computer-related entity, eitherhardware, a combination of hardware and software, software, or softwarein execution. For example, a component may be, but is not limited tobeing, a process running on a processor, a processor, an object, aninstance, an executable, a thread of execution, a program, and/or acomputer. By way of illustration, both an application running on acomputer and the computer can be a component. One or more components mayreside within a process and/or thread of execution and a component maybe localized on one computer and/or distributed between two or morecomputers.

The word “exemplary” or various forms thereof are used herein to meanserving as an example, instance, or illustration. Any aspect or designdescribed herein as “exemplary” is not necessarily to be construed aspreferred or advantageous over other aspects or designs. Furthermore,examples are provided solely for purposes of clarity and understandingand are not meant to limit or restrict the claimed subject matter orrelevant portions of this disclosure in any manner It is to beappreciated a myriad of additional or alternate examples of varyingscope could have been presented, but have been omitted for purposes ofbrevity.

The conjunction “or” as used this description and appended claims in isintended to mean an inclusive “or” rather than an exclusive “or,” unlessotherwise specified or clear from context. In other words, “‘X’ or ‘Y’”is intended to mean any inclusive permutations of “X” and “Y.” Forexample, if “‘A’ employs ‘X,’” “‘A employs ‘Y,’” or “‘A’ employs both‘A’ and ‘B,’” then “‘A’ employs ‘X’ or ‘Y’” is satisfied under any ofthe foregoing instances.

As used herein, the term “inference” or “infer” refers generally to theprocess of reasoning about or inferring states of the system,environment, and/or user from a set of observations as captured viaevents and/or data. Inference can be employed to identify a specificcontext or action, or can generate a probability distribution overstates, for example. The inference can be probabilistic—that is, thecomputation of a probability distribution over states of interest basedon a consideration of data and events. Inference can also refer totechniques employed for composing higher-level events from a set ofevents and/or data. Such inference results in the construction of newevents or actions from a set of observed events and/or stored eventdata, whether or not the events are correlated in close temporalproximity, and whether the events and data come from one or severalevent and data sources. Various classification schemes and/or systems(e.g., support vector machines, neural networks, expert systems,Bayesian belief networks, fuzzy logic, data fusion engines . . . ) canbe employed in connection with performing automatic and/or inferredaction in connection with the claimed subject matter.

Furthermore, to the extent that the terms “includes,” “contains,” “has,”“having” or variations in form thereof are used in either the detaileddescription or the claims, such terms are intended to be inclusive in amanner similar to the term “comprising” as “comprising” is interpretedwhen employed as a transitional word in a claim.

In order to provide a context for the claimed subject matter, FIG. 10 aswell as the following discussion are intended to provide a brief,general description of a suitable environment in which various aspectsof the subject matter can be implemented. The suitable environment,however, is only an example and is not intended to suggest anylimitation as to scope of use or functionality.

While the above disclosed system and methods can be described in thegeneral context of computer-executable instructions of a program thatruns on one or more computers, those skilled in the art will recognizethat aspects can also be implemented in combination with other programmodules or the like. Generally, program modules include routines,programs, components, data structures, among other things that performparticular tasks and/or implement particular abstract data types.Moreover, those skilled in the art will appreciate that the abovesystems and methods can be practiced with various computer systemconfigurations, including single-processor, multi-processor ormulti-core processor computer systems, mini-computing devices, mainframecomputers, as well as personal computers, hand-held computing devices(e.g., personal digital assistant (PDA), phone, watch . . . ),microprocessor-based or programmable consumer or industrial electronics,and the like. Aspects can also be practiced in distributed computingenvironments where tasks are performed by remote processing devices thatare linked through a communications network. However, some, if not allaspects of the claimed subject matter can be practiced on stand-alonecomputers. In a distributed computing environment, program modules maybe located in one or both of local and remote memory storage devices.

With reference to FIG. 10, illustrated is an example general-purposecomputer 1010 or computing device (e.g., desktop, laptop, server,hand-held, programmable consumer or industrial electronics, set-top box,game system . . . ). The computer 1010 includes one or more processor(s)1020, memory 1030, system bus 1040, mass storage 1050, and one or moreinterface components 1070. The system bus 1040 communicatively couplesat least the above system components. However, it is to be appreciatedthat in its simplest form the computer 1010 can include one or moreprocessors 1020 coupled to memory 1030 that execute various computerexecutable actions, instructions, and or components stored in memory1030.

The processor(s) 1020 can be implemented with a general purposeprocessor, a digital signal processor (DSP), an application specificintegrated circuit (ASIC), a field programmable gate array (FPGA) orother programmable logic device, discrete gate or transistor logic,discrete hardware components, or any combination thereof designed toperform the functions described herein. A general-purpose processor maybe a microprocessor, but in the alternative, the processor may be anyprocessor, controller, microcontroller, or state machine. Theprocessor(s) 1020 may also be implemented as a combination of computingdevices, for example a combination of a DSP and a microprocessor, aplurality of microprocessors, multi-core processors, one or moremicroprocessors in conjunction with a DSP core, or any other suchconfiguration.

The computer 1010 can include or otherwise interact with a variety ofcomputer-readable media to facilitate control of the computer 1010 toimplement one or more aspects of the claimed subject matter. Thecomputer-readable media can be any available media that can be accessedby the computer 1010 and includes volatile and nonvolatile media, andremovable and non-removable media. By way of example, and notlimitation, computer-readable media may comprise computer storage mediaand communication media.

Computer storage media includes volatile and nonvolatile, removable andnon-removable media implemented in any method or technology for storageof information such as computer-readable instructions, data structures,program modules, or other data. Computer storage media includes, but isnot limited to memory devices (e.g., random access memory (RAM),read-only memory (ROM), electrically erasable programmable read-onlymemory (EEPROM) . . . ), magnetic storage devices (e.g., hard disk,floppy disk, cassettes, tape . . . ), optical disks (e.g., compact disk(CD), digital versatile disk (DVD) . . . ), and solid state devices(e.g., solid state drive (SSD), flash memory drive (e.g., card, stick,key drive . . . ) . . . ), or any other medium which can be used tostore the desired information and which can be accessed by the computer1010.

Communication media typically embodies computer-readable instructions,data structures, program modules, or other data in a modulated datasignal such as a carrier wave or other transport mechanism and includesany information delivery media. The term “modulated data signal” means asignal that has one or more of its characteristics set or changed insuch a manner as to encode information in the signal. By way of example,and not limitation, communication media includes wired media such as awired network or direct-wired connection, and wireless media such asacoustic, RF, infrared and other wireless media. Combinations of any ofthe above should also be included within the scope of computer-readablemedia.

Memory 1030 and mass storage 1050 are examples of computer-readablestorage media. Depending on the exact configuration and type ofcomputing device, memory 1030 may be volatile (e.g., RAM), non-volatile(e.g., ROM, flash memory . . . ) or some combination of the two. By wayof example, the basic input/output system (BIOS), including basicroutines to transfer information between elements within the computer1010, such as during start-up, can be stored in nonvolatile memory,while volatile memory can act as external cache memory to facilitateprocessing by the processor(s) 1020, among other things.

Mass storage 1050 includes removable/non-removable,volatile/non-volatile computer storage media for storage of largeamounts of data relative to the memory 1030. For example, mass storage1050 includes, but is not limited to, one or more devices such as amagnetic or optical disk drive, floppy disk drive, flash memory,solid-state drive, or memory stick.

Memory 1030 and mass storage 1050 can include, or have stored therein,operating system 1060, one or more applications 1062, one or moreprogram modules 1064, and data 1066. The operating system 1060 acts tocontrol and allocate resources of the computer 1010. Applications 1062include one or both of system and application software and can exploitmanagement of resources by the operating system 1060 through programmodules 1064 and data 1066 stored in memory 1030 and/or mass storage1050 to perform one or more actions. Accordingly, applications 1062 canturn a general-purpose computer 1010 into a specialized machine inaccordance with the logic provided thereby.

All or portions of the claimed subject matter can be implemented usingstandard programming and/or engineering techniques to produce software,firmware, hardware, or any combination thereof to control a computer torealize the disclosed functionality. By way of example and notlimitation, the reactive programming system 100, or portions thereof,can be, or form part, of an application 1062, and include one or moremodules 1064 and data 1066 stored in memory and/or mass storage 1050whose functionality can be realized when executed by one or moreprocessor(s) 1020.

In accordance with one particular embodiment, the processor(s) 1020 cancorrespond to a system on a chip (SOC) or like architecture including,or in other words integrating, both hardware and software on a singleintegrated circuit substrate. Here, the processor(s) 1020 can includeone or more processors as well as memory at least similar toprocessor(s) 1020 and memory 1030, among other things. Conventionalprocessors include a minimal amount of hardware and software and relyextensively on external hardware and software. By contrast, an SOCimplementation of processor is more powerful, as it embeds hardware andsoftware therein that enable particular functionality with minimal or noreliance on external hardware and software. For example, the reactiveprogramming system 100 and/or associated functionality can be embeddedwithin hardware in a SOC architecture.

The computer 1010 also includes one or more interface components 1070that are communicatively coupled to the system bus 1040 and facilitateinteraction with the computer 1010. By way of example, the interfacecomponent 1070 can be a port (e.g., serial, parallel, PCMCIA, USB,FireWire . . . ) or an interface card (e.g., sound, video . . . ) or thelike. In one example implementation, the interface component 1070 can beembodied as a user input/output interface to enable a user to entercommands and information into the computer 1010 through one or moreinput devices (e.g., pointing device such as a mouse, trackball, stylus,touch pad, keyboard, microphone, joystick, game pad, satellite dish,scanner, camera, other computer . . . ). In another exampleimplementation, the interface component 1070 can be embodied as anoutput peripheral interface to supply output to displays (e.g., CRT,LCD, plasma . . . ), speakers, printers, and/or other computers, amongother things. Still further yet, the interface component 1070 can beembodied as a network interface to enable communication with othercomputing devices (not shown), such as over a wired or wirelesscommunications link.

What has been described above includes examples of aspects of theclaimed subject matter. It is, of course, not possible to describe everyconceivable combination of components or methodologies for purposes ofdescribing the claimed subject matter, but one of ordinary skill in theart may recognize that many further combinations and permutations of thedisclosed subject matter are possible. Accordingly, the disclosedsubject matter is intended to embrace all such alterations,modifications, and variations that fall within the spirit and scope ofthe appended claims.

What is claimed is:
 1. A method of facilitating reactive programming,comprising: employing at least one processor configured to executecomputer-executable instructions stored in memory to perform thefollowing acts: receiving a non-reactive expression; producing areactive expression from the non-reactive expression, wherein thereactive expression is a reactive version of the non-reactiveexpression; and generating an optimized version of the reactiveexpression that reduces computational work based on one or more inputsequences specified by the reactive expression and frequency at whichthe one or more input sequences produce elements.
 2. The method of claim1, generating the optimized version further comprises eliminatingmultiple subscriptions to a single source.
 3. The method of claim 1,generating the optimized version further comprises applying one or moredomain-specific optimizations.
 4. The method of claim 1, generating theoptimized version further comprises generating code that restrictsreevaluation of the reactive expression to instances where an inputsequence value changes from a previous value.
 5. The method of claim 1further comprises generating the optimized version of the reactiveexpression dynamically at run time.
 6. The method of claim 5 furthercomprises generating the optimized version of the reactive expression asa function of a predetermined threshold.
 7. The method of claim 1,generating the optimized version further comprises assigning shortestpath length in in a tree representation of the expression to an inputsequence of the one or more input sequences with highest frequency ofelement production.
 8. A system that facilitates reactive programming,comprising: a processor coupled to a memory, the processor configured toexecute the following computer-executable components stored in thememory: a first component configured to automatically generate areactive expression from a non-reactive expression, wherein the reactiveexpression is a reactive version of the non-reactive expression; and asecond component configured to optimize the reactive expression toreduce computational work based on one or more input sequences specifiedby the reactive expression and a frequency at which the one or moreinput sequences produce elements.
 9. The system of claim 8, the secondcomponent is further configured to alter the reactive expression tolimit reevaluation of at least parts of the reactive expression.
 10. Thesystem of claim 8, the second component is further configured to alterthe reactive expression to optimize for a particular domain.
 11. Thesystem of claim 8, the second component is further configured to filterout identical contiguous values.
 12. The system of claim 8 furthercomprises a third component external to the first component configuredto rewrite the reactive expression based on a domain.
 13. A method offacilitating reactive programming, comprising: employing at least oneprocessor configured to execute computer-executable instructions storedin memory to perform the following acts automatically: receiving anon-reactive expression; generating a reactive expression from thenon-reactive expression, wherein the reactive expression is a reactiveversion of the non-reactive expression; and optimizing the reactiveexpression to reduce computational work based on one or more inputsequences specified by the reactive expression and frequency at whichthe one or more input sequences produce elements.
 14. The method ofclaim 13, optimizing the reactive expression further compriseseliminating multiple subscriptions to a single source.
 15. The method ofclaim 13, optimizing the reactive expression further comprisesrestricting re-computation of the reactive expression to instances wherean input sequence value changes from a previous value.
 16. The method ofclaim 13, optimizing the reactive expression further comprisesre-writing the reactive expression based on domain specific information.17. A computer-readable storage medium having instructions storedthereon that enable at least one processor to perform a method uponexecution of the instructions, the method comprising: receiving anon-reactive expression; producing a reactive expression automaticallyfrom the non-reactive expression, wherein the reactive expression is areactive version of the non-reactive expression; and generating anoptimized version of the reactive expression automatically that reducescomputational work based on one or more input sequences specified by thereactive expression and frequency at which the one or more inputsequences produce elements.
 18. The computer-readable storage medium ofclaim 17, the method further comprises eliminating multiplesubscriptions to duplicate input sequences from the reactive expression.19. The computer-readable storage medium of claim 17, the method furthercomprises generating the optimized version of the reactive expressionautomatically based on domain specific information.
 20. Thecomputer-readable storage medium of claim 17, generating the optimizedversion further comprises assigning shortest path length in in a treerepresentation of the expression to an input sequence of the one or moreinput sequences with highest frequency of element production.